/**
 * Created by jijin on 2017/7/9.
 */
import React, { Component } from 'react';
import {
  View,
  StyleSheet,
  Platform,
  BackAndroid
} from 'react-native';
import ArticleList from "../components/article/article-list";
import {AppColors, AppSizes} from '../style';
import NavBar from '../components/navbar';
import HardWareBackPress from '../utils/handle-back-btn-press';

export default class Articles extends Component {

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    BackAndroid.addEventListener('hardwareBackPress', HardWareBackPress.bind(this));
  }

  componentWillUnmount() {
    BackAndroid.removeEventListener('hardwareBackPress', HardWareBackPress.bind(this));
  }

  render() {
    return (
      <View style={styles.container}>
        <ArticleList navigator={this.props.navigator}/>
        <NavBar
          leftOn={true}
          title={this.props.title}
          onLeftPress={() => Platform.OS === 'android' && this.props.openMenu()}
        />
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: AppColors.background,
    paddingTop: AppSizes.navbarHeight + AppSizes.statusBarHeight,
    marginBottom: Platform.OS === 'ios' ? AppSizes.navbarHeight : 0
  }
});